import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * .
 *
 * @author xuyayuan
 * @date 2021/10/8 11:44
 */
public class MapToListDemo {
    public static void main(String[] args) {
        Map<String,String> map=new HashMap<>();
        map.put("1","AAAA");
        map.put("2","BBBB");
        map.put("3","CCCC");
        map.put("4","DDDD");
        map.put("5","EEEE");

        // 转换 map键和值通过_拼接转List
        List<Object> list= map.entrySet().stream().map(et ->et.getKey()+"_"+et.getValue()).collect(Collectors.toList());
        System.out.println(" 转换 map键和值通过_拼接转List");
        list.forEach(obj-> System.out.println(obj));

        // 收集map中的key为list
        List<Object> keyList = map.entrySet().stream().map(emt -> emt.getKey()).collect(Collectors.toList());
        System.out.println(" 收集map中的key为list");
        keyList.forEach(obj-> System.out.println(obj));

        // 收集map中的value为list
        List<Object> valueList = map.entrySet().stream().map(emt -> emt.getValue()).collect(Collectors.toList());
        System.out.println("收集map中的value为list");
        valueList.forEach(obj-> System.out.println(obj));
    }
}
